﻿@using KMF.WebUI.Areas.KMFadmin.CustomHelpers
@using KMF.WebUI.Areas.KMFadmin.Models
@model IEnumerable<KMF.Common.ViewProductTagListDto>
@{
    ViewBag.Title = "Danh sách các Tags";
    Layout = "~/Areas/KMFadmin/Views/Shared/_layout.cshtml";
}

<nav>
    <div id="jCrumbs" class="breadCrumb module">
        <ul>
            <li><a href="@Url.Action("Index","AdminHome")"><i class="bootstrap icon-home"></i></a></li>
            <li><a href="javascript:void(0)">Danh sách các tags</a> </li>
        </ul>
    </div>
</nav>

<table class="table-odd table-plist">
    <colgroup>
        <col style="width: 30px"/>
        <col/>
        <col style="width: 30px"/>
    </colgroup>
    <tr>
        <th scope="col">STT</th>
        <th scope="col">Tên tag</th>
        <th scope="col"></th>
    </tr>
    @foreach (var item in Model)
    {
        <tr class="@string.Format("bn-{0}", item.Id)">
            <td>@item.STT</td>
            <td>
                @item.Name
            </td>
            <td>
                @Ajax.ActionLink("i","EditTagForm", new { id = item.Id }, new AjaxOptions
                                                         {
                                                             OnBegin = "ShowLoading",
                                                             OnSuccess = "AjaxReturnDataEditTag",
                                                             OnComplete = "HideLoading"
                                                         }, new { @class = "icon-edit-v2 fl-l bootstrapTangoSmall" })
                
            </td>
        </tr>
    }
</table>

<div class="p-paging">
    @Html.PageLinks((PageInfo)ViewBag.PageInfo, i => Url.Action("Index", "AdminProductTag", new { page = i }))
</div>

@section scripts
{
    <script src="~/Areas/KMFadmin/Scripts/jquery.unobtrusive-ajax.min.js"></script>
    <script type="text/javascript">       

        //------- Ajax kết quả trả về khi click nút Edit Tag ----------------
        function AjaxReturnDataEditTag(htmlFragment) {
            $('#wraper').append(htmlFragment);
        }

        //------- AjaxForm Submit kết quả trả về khi sumit form chỉnh sửa thông tin product tag ---------------------
        function AjaxReturnDataEditTagForm(data) {
            if (data.Result) {
                $('.popup-wap').fadeOut();
                $('.popup-wap').remove();
                $('tr.bn-' + data.Id).children('td').eq(1).text(data.Name);
            }
            else {
                alert('Đã có lỗi xảy ra!');
            }
        }
    </script>
}

